<!-- 报警成功页面 -->
<template>
	<view class="bg-white" style="height: 100vh;">
		<cu-custom bgColor="bg-white">
			<block style="color: ##777777;font-size: 48rpx;" slot="content">{{title}}</block>
		</cu-custom>
		<view style=" margin: 0 60rpx;height: 60vh;display: flex;flex-direction: column;justify-content: center;">
			<text>{{msg}}</text>
			<view style="display: flex;flex-direction: row;justify-content: space-around;" class="margin-top">
				<button class="cu-btn" @click="jshq">结束火情</button>
				<button class="cu-btn" @click="back">返回首页</button>
			</view>
		</view>

		<view class="cu-modal" :class="model">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">
					<button class="cu-btn text-blue" @click="hqcancle">取消</button>
					<button class="cu-btn text-green" @click="tjjshq">确定</button>
				</view>
				<view class="padding-xl">
					如火情未扑灭，恶意结束火情信息将承担相应法律责任
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import * as constants from '@/common/config.js';
	export default {
		onShow() {

		},
		onLoad(option) {
			this.ucId = option.noticeId
			this.audioId = option.audioId
			this.xq()
		},
		data() {
			return {
				title: '',
				msg: '',
				ucId: '',
				audioId: '',
				innerAudioContext: null,
				model: '',
				imgUrl: ''
			}
		},
		methods: {
			hqcancle() {
				this.model = ''
			},
			playAudio(path) {
				this.innerAudioContext = uni.createInnerAudioContext();
				this.innerAudioContext.src = path
				this.innerAudioContext.play()
			},
			stopAudio() {
				if (this.innerAudioContext) {
					this.innerAudioContext.stop()
				}
			},
			back() {
				this.stopAudio()
				uni.navigateBack({
					delta: 99
				})
			},
			xq() {
				let params = {
					"ucId": this.ucId
				}
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: '/wx/notice/getInNoticeVo',
					data: {
						...params
					}
				}).then(function(res) {
					console.info("通知响起" + res.data)
					that.msg = res.data.data.noticeContent
					that.title = res.data.data.noticeName

					// 音频
					let path = ''
					if (this.audioId == 0) {

					} else if (this.audioId == 1) {
						path = "https://www.cetczhxf.com/mp3/first.mp3"
					} else if (this.audioId == 2) {
						path = "https://www.cetczhxf.com/mp3/second.mp3"
					} else if (this.audioId == 3) {
						path = "https://www.cetczhxf.com/mp3/third.mp3"
					} else if (this.audioId == 4) {
						path = "https://www.cetczhxf.com/mp3/fourth.mp3"
					} else if (this.audioId == 5) {
						path = "https://www.cetczhxf.com/mp3/alarm.mp3"
					} else if (this.audioId == 6) {
						path = "https://www.cetczhxf.com/mp3/sixth.mp3"
					} else if (this.audioId == 7) {
						path = "https://www.cetczhxf.com/mp3/seventh.mp3"
					} else if (this.audioId == 8) {
						path = "https://www.cetczhxf.com/mp3/eighth.mp3"
					}
					this.playAudio(path)


				}).catch(function(e) {

				})
			},
			jshq() {
				this.model = 'show'
			},
			up() {
				console.info("IIMMGG:" + this.imgUrl)
				// 封装参数
				let vparams = {
					"ucId": this.ucId,
					"confirmFireFile": this.imgUrl
				}
				console.info("参数1111:" + JSON.stringify(vparams))
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/firemanage/generateFireFinishPutFire',
					data: {
						...vparams
					}
				}).then(function(res) {
					console.info(res)

					if (res.data.code == 0) {
						uni.navigateBack({
							delta: 2
						})
					}



				}).catch(function(e) {
					uni.showToast({
						title: '操作失败',
						icon: 'error'
					})
				})
			},
			uploadFile(path) {
				let that = this
				let app = getApp()
				let token = app.globalData.getToken('authorization')
				const uploadTask = uni.uploadFile({
					url: constants.API + 'wx/common/upload',
					filePath: path,
					header: {
						"authorization": token
					},
					name: 'file',
					success(uploadFileRes)  {
						let obj = JSON.parse(uploadFileRes.data)
						console.info("title:"+that.title)
						console.info(obj.data)
						that.imgUrl = obj.data;
						console.info("xxxxxxxxxxxxx" + that.imgUrl)
						
						that.up()
					}
				})
				// uploadTask.onProgressUpdate((res) => {
				// 	console.info(">>>:::"+JSON.stringify(res))
				// 	console.log('上传进度' + res.progress);
				// 	console.log('已经上传的数据长度' + res.totalBytesSent);
				// 	console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);

				// 	// 测试条件，取消上传任务。
				// 	if (res.progress == 100) {
				// 		that.up()
				// 	}
				// });
			},
			tjjshq() {
				// 首先拍照片
				let that = this
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //从相册选择
					success: (res) => {
						let path = res.tempFilePaths

						// 上传
						this.uploadFile(path[0]);


					}
				});



			},
		}
	}
</script>

<style>

</style>
